package com.baitiaojun.common.enums.impl;

import cn.hutool.core.util.ArrayUtil;
import com.baitiaojun.common.enums.Enums;
import lombok.AllArgsConstructor;

import java.util.Arrays;

/**
 * 数据源
 *
 * @author baitiaojun
 */
@AllArgsConstructor
public enum DataSourceTypeEnums implements Enums {

    DEFAULT_DB(0, "default_db"),
    SLAVE_DB(1, "slave_db"),
    ;

    private final Integer code;

    private final String name;

    @Override
    public Enums valueOf(Integer code) {
        return ArrayUtil.firstMatch(item -> item.getCode().equals(code), values());
    }

    @Override
    public int[] array() {
        return Arrays.stream(values()).mapToInt(DataSourceTypeEnums::getCode).toArray();
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getName() {
        return name;
    }
}